/*
 * Copyright (c) 2025 Li Auto Inc. and its affiliates
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef SRC_CPP_RTPS_TRANSPORT_IPCCHANNELRESOURCE_H_
#define SRC_CPP_RTPS_TRANSPORT_IPCCHANNELRESOURCE_H_

#include <queue>

#include <ertps/utils/LocatorAlias.h>
#include <transport/ChannelResource.h>

namespace vbs {
namespace transport {

class ReceiverResource;
class IPCTransport;

class IPCChannelResource : public ChannelResource {
 public:
    IPCChannelResource(IPCTransport* transport, uint32_t maxMsgSize, std::shared_ptr<ReceiverResource> receiver);

    ~IPCChannelResource() override;

    inline void message_receiver(std::shared_ptr<ReceiverResource> receiver) { message_receiver_ = receiver; }

    inline ReceiverResource* message_receiver() { return message_receiver_.get(); }

    inline void disable() override { ChannelResource::disable(); }

 protected:
    /**
     * Function to be called from a new thread, which takes cares of performing a blocking receive
     * operation on the ReceiveResource
     */
    void perform_listen_operation(void);

 private:
    std::shared_ptr<ReceiverResource> message_receiver_;  // Associated Readers/Writers inside of MessageReceiver

    IPCTransport* transport_;

    IPCChannelResource(const IPCChannelResource&) = delete;
    IPCChannelResource& operator=(const IPCChannelResource&) = delete;
};

}  // namespace transport
}  // namespace vbs

#endif  // SRC_CPP_RTPS_TRANSPORT_IPCCHANNELRESOURCE_H_
